<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .father {
        width: 200px;
        height: 200px;
        background-color: green;
      }
      .son {
        width: 100px;
        height: 100px;
        background-color: red;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <h2>事件修饰符</h2>
      <!-- 
        .stop 表示阻止事件冒泡 √
        .prevent 阻止默认行为 √
        .self 只能点击自己执行
        .capture 捕获行为
        .once 只能执行一次
       -->
      <div class="father" @click="fatherClick">
        <div class="son" @click.stop="sonClick"></div>
      </div>

      <form @submit.prevent="handleSubmit">
        <input type="text" />
        <input type="submit" />
      </form>

      <h2>按键修饰符</h2>
      <!-- 在vue3中，按键修饰符只能用按键名称 -->
      <!-- 在vue2中，按键修饰符可以用按键名称和按键码 -->
      <input type="text" @keyup.enter="handleKeyUp" />

      <h2>系统按键修饰符</h2>
      <button @click.ctrl.exact="fn">btn</button>
    </div>

    <script src="./lib/vue3.js"></script>
    <script>
      const { createApp } = Vue;

      createApp({
        data() {
          return {};
        },
        methods: {
          fatherClick() {
            console.log("fatherClick");
          },
          sonClick() {
            // 阻止事件冒泡
            // e.stopPropagation();
            console.log("sonClick");
          },
          handleSubmit() {
            console.log(123);
          },
          handleKeyUp(e) {
            // console.log(e.keyCode);
            // if (e.keyCode === 13) {
            //   console.log(e.target.value);
            // }
            console.log(e.key);
          },
          fn() {
            console.log("fn");
          },
        },
      }).mount("#app");
    </script>
  </body>
</html>
